#include "geometry.h"

int main()
{
	int n, m, mj, answer, in_hole = -1;
	point p, in_p, p_e;
	std::vector<point> polygon;

	std::cin >> p.x >> p.y;
	std::cin >> n;

	for (int i = 0; i < n; i++)
	{
		std::cin >> in_p.x >> in_p.y;
		MAXX = std::max(MAXX, in_p.x);
		polygon.push_back(in_p);
	}
	polygon.push_back(polygon[0]);

	p_e.x = MAXX + 1488;
	p_e.y = p.y + 0.1488;

	answer = in_polygon(polygon, p, p_e);

	std::cin >> m;

	for (int i = 0; i < m; i++)
	{
		std::cin >> mj;
		polygon.clear();
		for (int j = 0; j < mj; j++)
		{
			std::cin >> in_p.x >> in_p.y;
			MAXX = std::max(MAXX, in_p.x);
			polygon.push_back(in_p);
		}
		polygon.push_back(polygon[0]);

		in_hole = in_polygon(polygon, p, p_e);
		if (in_hole != -1)
			break;
	}

	if (answer == -1 || in_hole == 1)
		std::cout << -1;
	if (answer == 0 || in_hole == 0)
		std::cout << 0;
	if (answer == 1 && in_hole == -1)
		std::cout << 1;
}